﻿using System;
using System.Collections.Generic;
using BLToolkit.DataAccess;
using BLToolkit.Mapping;
using BLToolkit.Data;
using System.Linq;

namespace Entities
{
    [TableName("Bills")]
    public class Bill : Card
    {
        [MapIgnore]
        private readonly DbManager _dataContext = new DbManager();

        public string CusID { get; set; }
        public string SelID { get; set; }
        public DateTime RequireDate { get; set; }

        [MapIgnore]
        public string CusName { 
            get {
                return _dataContext.GetTable<Member>().Where(mb => mb.UseName == CusID).FirstOrDefault().FullName; 
            } 
        }

        [MapIgnore]
        public string SalerName {
            get
            {
                return _dataContext.GetTable<Member>().Where(mb => mb.UseName == SelID).FirstOrDefault().FullName;
            } 
        }

        [Association(ThisKey = "CusID", OtherKey = "UseName", CanBeNull = false)]
        public Member CusInfo { get; set; }

        [Association(ThisKey = "SelID", OtherKey = "UseName", CanBeNull = false)]
        public Member SelerInfo { get; set; }
    }
}
